package leetcode_day._2022._202201._0110;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/1/4 14:08
 * 一周中的第几天
 * 算法：模拟
 * 给出的日期一定是在 1971 到 2100 年之间的有效日期。
 * 1970 年的最后一天是星期四
 */
public class _03_1185 {
    static String[] weeks = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    static int[] months = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    public String dayOfTheWeek(int day, int month, int year) {
        int cnt = 4;
        for (int i = 1971; i < year; i++) cnt += (i % 4 == 0 && i % 100 != 0) || i % 400 == 0 ? 366 : 365;
        for (int i = 1; i < month; i++) {
            cnt += months[i - 1];
            if (i == 2 && (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ++cnt;
        }
        cnt += day;
        return weeks[cnt % 7];
    }

}
